package com.minisoft.jd.seckill;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Console;
import cn.hutool.cron.CronUtil;
import cn.hutool.cron.task.Task;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;

import java.io.File;

/**
 * @author JueSu
 * @description: TODO
 * @date 2021/11/27 21:25
 */
public class CronUtilTest {

    public static void main(String[] args) {

        File f = new File("text.txt");
        System.out.println(f.getAbsolutePath());

        CronUtil.schedule("*/1 * * * * *", new Task() {
            public void execute() {
                JSONObject jdTime = JSONUtil.parseObj(HttpUtil.get("https://api.m.jd.com/client.action?functionId=queryMaterialProducts&client=wh5"));
                Console.log("jd {}->{}",jdTime.getStr("currentTime"),DateUtil.date());
                System.out.println(DateUtil.spendMs(jdTime.getLong("currentTime2")));
            }
        });
        // 支持秒级别定时任务
        CronUtil.setMatchSecond(true);
        CronUtil.start();
    }
}
